﻿namespace WMS6.Web.OrderManagement
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.OrderMgtServiceRef;

    public class SalesOrder : BasePage
    {
        protected HtmlInputButton btnAction;
        protected Button btnAddDetail;
        protected Button btnCopy;
        protected Button btnDelete;
        protected Button btnDeleteDetail;
        protected Button btnGoBack;
        protected Button btnNew;
        protected Button btnQuicklyInput;
        protected Button btnRefresh;
        protected Button btnSave;
        protected DropDownList ddlPaymentMode;
        protected DropDownList ddlPriority;
        protected DropDownList ddlStatus;
        protected DropDownList ddlTransportMode;
        protected DropDownList ddlType;
        protected HtmlForm F3021;
        protected GridView gvSalesOrderDetail;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnCopy;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnIsRequiredExternalID;
        protected HtmlInputHidden hdnLineID;
        protected HtmlInputHidden hdnOrderID;
        protected HtmlInputHidden hdnPageQty;
        protected HtmlInputHidden hdnPageType;
        protected HtmlInputButton htmlbtnReport;
        protected HtmlImage img1;
        protected HtmlImage imgBillToID;
        protected HtmlImage imgConsigneeID;
        protected HtmlImage imgOwnerID;
        protected Label lblActualShipDate;
        protected Label lblB_Address;
        protected Label lblB_City;
        protected Label lblB_Company;
        protected Label lblB_Contact1;
        protected Label lblB_Contact2;
        protected Label lblB_Country;
        protected Label lblB_Email1;
        protected Label lblB_Email2;
        protected Label lblB_Fax1;
        protected Label lblB_Fax2;
        protected Label lblB_Phone1;
        protected Label lblB_Phone2;
        protected Label lblB_Prov;
        protected Label lblB_Zip;
        protected Label lblBillToID;
        protected Label lblC_Address;
        protected Label lblC_City;
        protected Label lblC_Contact1;
        protected Label lblC_Contact2;
        protected Label lblC_Country;
        protected Label lblC_Email1;
        protected Label lblC_Email2;
        protected Label lblC_Fax1;
        protected Label lblC_Fax2;
        protected Label lblC_Phone1;
        protected Label lblC_Phone2;
        protected Label lblC_Prov;
        protected Label lblC_Zip;
        protected Label lblCompany;
        protected Label lblConsigneeID;
        protected Label lblCustomerID;
        protected Label lblDeliveryDate;
        protected Label lblExternOrderID;
        protected Label lblMsg;
        protected Label lblOrderDate;
        protected Label lblOrderID;
        protected Label lblOrderID1;
        protected Label lblOrderID2;
        protected Label lblOwnerID;
        protected Label lblPaymentMode;
        protected Label lblPriority;
        protected Label lblRemark;
        protected Label lblRequestedDeliveryDate;
        protected Label lblSalesOrder;
        protected Label lblStatus;
        protected Label lblTotalQty;
        protected Label lblTransportMode;
        protected Label lblTye;
        protected Label lblUdf1;
        protected Label lblUdf10;
        protected Label lblUdf2;
        protected Label lblUdf3;
        protected Label lblUdf4;
        protected Label lblUdf5;
        protected Label lblUdf6;
        protected Label lblUdf7;
        protected Label lblUdf8;
        protected Label lblUdf9;
        protected LinkButton lnkbtnPrintSO;
        protected LinkButton lnkbtnSalesOrderCancel;
        protected LinkButton lnkbtnSalesOrderSubmit;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Label one3;
        protected Label one4;
        protected Label one5;
        protected ScriptManager ScriptManager1;
        protected HtmlTableCell tdlnkbtnPrintsO;
        protected HtmlTableCell tdlnkbtnSalesOrderCancel;
        protected HtmlTableCell tdlnkbtnSalesOrderSubmit;
        protected TextBox txtActualShipDate;
        protected TextBox txtB_Address;
        protected TextBox txtB_City;
        protected TextBox txtB_Company;
        protected TextBox txtB_Contact1;
        protected TextBox txtB_Contact2;
        protected TextBox txtB_Country;
        protected TextBox txtB_Email1;
        protected TextBox txtB_Email2;
        protected TextBox txtB_Fax1;
        protected TextBox txtB_Fax2;
        protected TextBox txtB_Phone1;
        protected TextBox txtB_Phone2;
        protected TextBox txtB_Prov;
        protected TextBox txtB_Zip;
        protected TextBox txtBillToID;
        protected TextBox txtC_Address;
        protected TextBox txtC_City;
        protected TextBox txtC_Company;
        protected TextBox txtC_Contact1;
        protected TextBox txtC_Contact2;
        protected TextBox txtC_Country;
        protected TextBox txtC_Email1;
        protected TextBox txtC_Email2;
        protected TextBox txtC_Fax1;
        protected TextBox txtC_Fax2;
        protected TextBox txtC_Phone1;
        protected TextBox txtC_Phone2;
        protected TextBox txtC_Prov;
        protected TextBox txtC_Zip;
        protected TextBox txtConsigneeID;
        protected TextBox txtCustomerID;
        protected TextBox txtDeliveryDate;
        protected TextBox txtExternOrderID;
        protected TextBox txtOrderDate;
        protected TextBox txtOrderID;
        protected TextBox txtOrderID1;
        protected TextBox txtOrderID2;
        protected TextBox txtOwnerID;
        protected TextBox txtRemark;
        protected TextBox txtRequestedDeliveryDate;
        protected TextBox txtTotalQty;
        protected TextBox txtUdf1;
        protected TextBox txtUdf10;
        protected TextBox txtUdf2;
        protected TextBox txtUdf3;
        protected TextBox txtUdf4;
        protected TextBox txtUdf5;
        protected TextBox txtUdf6;
        protected TextBox txtUdf7;
        protected TextBox txtUdf8;
        protected TextBox txtUdf9;

        private void AuthenticationExternalIDByOwner()
        {
            if (string.IsNullOrEmpty(this.hdnIsRequiredExternalID.Value))
            {
                TradePartnerInfo owner = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtOwnerID.Text, "TRADE_PARTNER") as TradePartnerInfo;
                if (owner != null)
                {
                    this.hdnIsRequiredExternalID.Value = owner.IsRequiredExternalID;
                }
            }
            if ((this.hdnIsRequiredExternalID.Value == "Y") && string.IsNullOrEmpty(this.txtExternOrderID.Text))
            {
                throw new Exception(base.GetGlobalMsgResource("F3100_022"));
            }
        }

        protected void btnAddDetail_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() == "NEW")
                {
                    if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F7100_002");
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,5);</script>", false);
                    }
                    else if (string.IsNullOrEmpty(this.txtOrderDate.Text.Trim()))
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F7100_003");
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,5);</script>", false);
                    }
                    else if (string.IsNullOrEmpty(this.txtRequestedDeliveryDate.Text.Trim()))
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F7100_004");
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,5);</script>", false);
                    }
                    else if (string.IsNullOrEmpty(this.txtCustomerID.Text.Trim()))
                    {
                        this.lblMsg.Text = "请输入客户代码!";
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,5);</script>", false);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(this.hdnOrderID.Value))
                        {
                            if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F7100_016");
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,5);</script>", false);
                                return;
                            }
                            this.InsertShippingOrderInfo();
                        }
                        base.Response.Redirect(string.Format("SalesOrderDetail.aspx?from={0}&ID={1}&LineID={2}&OwnerID={3}", new object[] { base.UrlEncode(this.hdnFrom.Value), base.UrlEncode(this.txtOrderID.Text.Trim()), base.UrlEncode(this.hdnLineID.Value), base.UrlEncode(this.txtOwnerID.Text.Trim()) }), false);
                    }
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7100_017");
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtOrderID.Text.Trim()))
            {
                try
                {
                    if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F7100_013");
                    }
                    else
                    {
                        List<string> orderID = new List<string> {
                            this.txtOrderID.Text.Trim()
                        };
                        this.lblMsg.Text = OrderMgtServiceClientProxy.GetInstance().DeleteSalesOrderInfo(orderID) + base.GetGlobalMsgResource("F7100_014");
                        this.btnSave.Enabled = false;
                        this.btnDelete.Enabled = false;
                        this.btnCopy.Enabled = false;
                        base.DataEntityViewState = null;
                    }
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7100_015") + ex.Message;
                }
            }
        }

        protected void btnDeleteDetail_Click(object sender, EventArgs e)
        {
            try
            {
                List<string> lineIDs = base.GetSelectedIDsInGridView(this.gvSalesOrderDetail, "LINEID");
                List<string> listStatus = base.GetSelectedIDsInGridView(this.gvSalesOrderDetail, "STATUS");
                if ((listStatus != null) && (listStatus.Count > 0))
                {
                    for (int i = 0; i < listStatus.Count; i++)
                    {
                        if (listStatus[i].ToUpper() != "NEW")
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F7100_018");
                            return;
                        }
                    }
                }
                if ((lineIDs == null) || (lineIDs.Count == 0))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7100_019");
                    return;
                }
                this.lblMsg.Text = OrderDetailMgtServiceClientProxy.GetInstance().DeleteSalesOrderDetail(this.txtOrderID.Text, lineIDs) + base.GetGlobalMsgResource("F7100_014");
                this.LoadData();
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F7100_015") + ex.Message;
            }
            this.SetSalesOrderInfo2From();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',5,5);</script>", false);
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("SalesOrderQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("SalesOrderList.aspx?from=edit", false);
                    break;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7100_002");
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,5);</script>", false);
                }
                else if (string.IsNullOrEmpty(this.txtOrderDate.Text.Trim()))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7100_003");
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,5);</script>", false);
                }
                else if (string.IsNullOrEmpty(this.txtRequestedDeliveryDate.Text.Trim()))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7100_004");
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,5);</script>", false);
                }
                else if (string.IsNullOrEmpty(this.txtCustomerID.Text.Trim()))
                {
                    this.lblMsg.Text = "请输入客户代码!";
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,5);</script>", false);
                }
                else
                {
                    this.AuthenticationExternalIDByOwner();
                    if (this.hdnFlag.Value == "1")
                    {
                        this.UpdateShippingOrderInfo();
                    }
                    else
                    {
                        this.InsertShippingOrderInfo();
                        this.btnAddDetail.Visible = true;
                        this.btnDeleteDetail.Visible = true;
                    }
                    this.hdnPageQty.Value = "0";
                }
            }
            catch (Exception ex)
            {
                base.ShowMsgLabel(this.lblMsg, ex.Message);
            }
        }

        protected void ConvertSalesOrder2ShippingOrder()
        {
            try
            {
                List<string> gInitLocal0 = new List<string> {
                    this.txtOrderID.Text.Trim()
                };
                string shippingOrderID = OrderMgtServiceClientProxy.GetInstance().ConvertSalesOrder2ShippingOrder(gInitLocal0);
                this.lblMsg.Text = "订单:" + this.txtOrderID.Text.Trim() + "提交成功!";
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = "转换失败:" + ex.Message;
            }
        }

        private void EnableButton(string status)
        {
            string CS40000 = status;
            if ((CS40000 != null) && (CS40000 == "Cancelled"))
            {
                this.btnAddDetail.Enabled = false;
                this.btnDeleteDetail.Enabled = false;
                this.btnRefresh.Enabled = false;
                this.btnSave.Enabled = false;
                this.btnDelete.Enabled = false;
                this.lnkbtnSalesOrderSubmit.Enabled = false;
                this.lnkbtnSalesOrderCancel.Enabled = false;
            }
        }

        protected void gvSalesOrderDetail_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F3021", this.gvSalesOrderDetail);
        }

        protected void gvSalesOrderDetail_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            (sender as GridView).PageIndex = e.NewPageIndex;
            (sender as GridView).DataSource = (base.DataEntityViewState as SalesOrderInfo).SalesOrderDetailInfos;
            (sender as GridView).DataBind();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',5,5) </script>", false);
        }

        protected void gvSalesOrderDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int i = this.gvSalesOrderDetail.PageIndex * this.gvSalesOrderDetail.PageSize;
                e.Row.Cells[2].Text = ((e.Row.RowIndex + 1) + i).ToString();
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuStyle"));
            }
        }

        protected void gvSalesOrderDetail_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                string sortDirection = string.Empty;
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    sortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    sortDirection = "ASC";
                }
                SalesOrderInfo ordersInfo = base.DataEntityViewState as SalesOrderInfo;
                DataView dv = CADataConverter.ToDataTable(ordersInfo.SalesOrderDetailInfos).DefaultView;
                dv.Sort = e.SortExpression + " " + sortDirection;
                base.BindData2GridView(this.gvSalesOrderDetail, dv);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',5,5);</script>", false);
            }
        }

        private void InsertShippingOrderInfo()
        {
            try
            {
                if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                {
                    this.lblMsg.Text = "请输入货主代码!";
                }
                else if (string.IsNullOrEmpty(this.txtCustomerID.Text.Trim()))
                {
                    this.lblMsg.Text = "请输入客户代码!";
                }
                else
                {
                    SalesOrderInfo ordersInfo = new SalesOrderInfo();
                    if (base.DataEntityViewState != null)
                    {
                        SalesOrderInfo SrcordersInfo = base.DataEntityViewState as SalesOrderInfo;
                        if ((this.hdnCopy.Value == "1") && ((SrcordersInfo.SalesOrderDetailInfos != null) && (SrcordersInfo.SalesOrderDetailInfos.Count > 0)))
                        {
                            ordersInfo.SalesOrderDetailInfos = SrcordersInfo.SalesOrderDetailInfos;
                        }
                    }
                    ordersInfo = this.SetOrdersInfo(ordersInfo);
                    ordersInfo.CreatedBy = base.UserInfo.UserID;
                    ordersInfo.UpdatedBy = base.UserInfo.UserID;
                    string orderID = OrderMgtServiceClientProxy.GetInstance().InsertSalesOrderInfo(ordersInfo);
                    this.txtOrderID.Text = orderID;
                    this.txtOrderID1.Text = orderID;
                    this.txtOrderID2.Text = orderID;
                    this.txtOrderID.Enabled = false;
                    this.txtOrderID1.Enabled = false;
                    this.txtOrderID2.Enabled = false;
                    this.hdnOrderID.Value = orderID;
                    this.hdnLineID.Value = "10";
                    this.lblMsg.Text = orderID + base.GetGlobalMsgResource("F7100_011");
                    this.hdnFlag.Value = "1";
                    base.DataEntityViewState = ordersInfo;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F7100_012") + ex.Message;
            }
        }

        protected void lnkbtnSalesOrderCancel_Click(object sender, EventArgs e)
        {
            if (this.ddlStatus.SelectedValue.ToUpper() == "SCHEDULED")
            {
                try
                {
                    string shippingOrderID = OrderMgtServiceClientProxy.GetInstance().SalesOrderCancel(this.txtOrderID.Text);
                    this.SetSalesOrderInfo2From();
                    this.lblMsg.Text = "销售订单 " + this.txtOrderID.Text.Trim() + " 取消成功!";
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = "取消失败:" + ex.Message;
                }
            }
            else
            {
                this.lblMsg.Text = "取消失败:单据状态不为提交,无法取消!";
            }
        }

        protected void lnkbtnSalesOrderSubmit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtOrderID.Text.Trim()))
            {
                this.lblMsg.Text = "请先保存销售订单再提交!";
            }
            else if (this.ddlStatus.SelectedValue.ToUpper() == "NEW")
            {
                this.ConvertSalesOrder2ShippingOrder();
                this.SetSalesOrderInfo2From();
            }
            else
            {
                this.lblMsg.Text = "提交失败:单据状态不为New,无法提交!";
            }
        }

        private void LoadData()
        {
            this.txtOrderDate.Text = base.GetPreferenceShortDate(DateTime.Now);
            this.txtRequestedDeliveryDate.Text = base.GetPreferenceShortDate(DateTime.Now);
            base.BindData2DDLBySysCode(this.ddlType, "SalesOrderType");
            base.BindData2DDLBySysCode(this.ddlStatus, "OrderStatus");
            base.BindData2DDLBySysCode(this.ddlPriority, "OrderPriority");
            base.BindData2DDLBySysCode(this.ddlPaymentMode, "PaymentTerms");
            base.BindData2DDLBySysCode(this.ddlTransportMode, "TransportMode");
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnOrderID.Value = base.Request.QueryString["ID"].ToString();
                this.SetSalesOrderInfo2From();
                this.hdnFlag.Value = "1";
            }
            else
            {
                base.SetDefaultOwner(this.txtOwnerID);
                base.SetDefaultCustomer(this.txtCustomerID);
                this.txtCustomerID_TextChanged(null, null);
            }
            if (string.IsNullOrEmpty(this.hdnLineID.Value))
            {
                this.hdnLineID.Value = "10";
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["detail"]))
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',5,5);</script>", false);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
            this.lblMsg.Text = "";
        }

        private SalesOrderInfo SetOrdersInfo(SalesOrderInfo ordersInfo)
        {
            DateTime dt = DateTime.Now;
            decimal outDec = new decimal(0, 0, 0, false, 1);
            ordersInfo.OrderID = this.txtOrderID.Text.Trim();
            ordersInfo.Status = this.ddlStatus.SelectedValue;
            ordersInfo.Type = this.ddlType.SelectedValue;
            if (DateTime.TryParse(this.txtOrderDate.Text.Trim(), out dt))
            {
                ordersInfo.OrderDate = DateTime.Parse(this.txtOrderDate.Text.Trim());
            }
            else
            {
                ordersInfo.OrderDate = dt;
            }
            ordersInfo.OwnerID = this.txtOwnerID.Text;
            ordersInfo.Priority = this.ddlPriority.SelectedValue;
            if (DateTime.TryParse(this.txtActualShipDate.Text.Trim(), out dt))
            {
                ordersInfo.ActualShipDate = DateTime.Parse(this.txtActualShipDate.Text.Trim());
            }
            else
            {
                ordersInfo.ActualShipDate = DateTime.Now;
            }
            if (!string.IsNullOrEmpty(this.txtRequestedDeliveryDate.Text))
            {
                ordersInfo.RequestedDeliveryDate = DateTime.Parse(this.txtRequestedDeliveryDate.Text);
            }
            ordersInfo.DeliveryDate = DateTime.Now;
            ordersInfo.DepartureDate = DateTime.Now;
            ordersInfo.TransportationMode = this.ddlTransportMode.SelectedValue;
            ordersInfo.ConsigneeID = this.txtCustomerID.Text;
            ordersInfo.CCompany = this.txtC_Company.Text;
            ordersInfo.CCity = this.txtC_City.Text;
            ordersInfo.CProv = this.txtC_Prov.Text;
            ordersInfo.CContact1 = this.txtC_Contact1.Text;
            ordersInfo.CContact2 = this.txtC_Contact2.Text;
            ordersInfo.CZip = this.txtC_Zip.Text;
            ordersInfo.CCountryCode = this.txtC_Country.Text;
            ordersInfo.CPhone1 = this.txtC_Phone1.Text;
            ordersInfo.CPhone2 = this.txtC_Phone2.Text;
            ordersInfo.CAddress = this.txtC_Address.Text;
            ordersInfo.CFax1 = this.txtC_Fax1.Text;
            ordersInfo.CFax2 = this.txtC_Fax2.Text;
            ordersInfo.CEmail1 = this.txtC_Email1.Text;
            ordersInfo.CEmail2 = this.txtC_Email2.Text;
            ordersInfo.BillToID = this.txtBillToID.Text;
            ordersInfo.BCompany = this.txtB_Company.Text;
            ordersInfo.BCity = this.txtB_City.Text;
            ordersInfo.BState = this.txtB_Prov.Text;
            ordersInfo.BContact1 = this.txtB_Contact1.Text;
            ordersInfo.BContact2 = this.txtB_Contact2.Text;
            ordersInfo.BZip = this.txtB_Zip.Text;
            ordersInfo.BCountryCode = this.txtB_Country.Text;
            ordersInfo.BPhone1 = this.txtB_Phone1.Text;
            ordersInfo.BPhone2 = this.txtB_Phone2.Text;
            ordersInfo.BAddress = this.txtB_Address.Text;
            ordersInfo.BFax1 = this.txtB_Fax1.Text;
            ordersInfo.BFax2 = this.txtB_Fax2.Text;
            ordersInfo.BEmail1 = this.txtB_Email1.Text;
            ordersInfo.BEmail2 = this.txtB_Email2.Text;
            ordersInfo.Remark = this.txtRemark.Text;
            ordersInfo.Udf1 = this.txtUdf1.Text;
            ordersInfo.Udf2 = this.txtUdf2.Text;
            ordersInfo.Udf3 = this.txtUdf3.Text;
            ordersInfo.Udf4 = this.txtUdf4.Text;
            ordersInfo.Udf5 = this.txtUdf5.Text;
            ordersInfo.Udf6 = this.txtUdf6.Text;
            ordersInfo.Udf7 = this.txtUdf7.Text;
            ordersInfo.Udf8 = this.txtUdf8.Text;
            ordersInfo.Udf9 = this.txtUdf9.Text;
            ordersInfo.Udf10 = this.txtUdf10.Text;
            ordersInfo.IsActive = "Y";
            ordersInfo.ExternOrderID = this.txtExternOrderID.Text;
            ordersInfo.Door = "";
            ordersInfo.Route = "";
            ordersInfo.Stop = "";
            return ordersInfo;
        }

        private void SetSalesOrderInfo2From()
        {
            string OrderID = this.hdnOrderID.Value.ToString();
            SalesOrderInfo orderInfo = OrderMgtServiceClientProxy.GetInstance().GetSalesOrderInfoByID(OrderID);
            base.DataEntityViewState = orderInfo;
            if (orderInfo != null)
            {
                this.txtOrderID.Text = orderInfo.OrderID;
                this.txtOrderID1.Text = orderInfo.OrderID;
                this.txtOrderID2.Text = orderInfo.OrderID;
                this.txtCustomerID.Text = orderInfo.ConsigneeID;
                this.ddlStatus.SelectedValue = orderInfo.Status;
                this.ddlType.SelectedValue = orderInfo.Type;
                this.ddlType.Enabled = false;
                this.txtOrderDate.Text = base.GetPreferenceShortDate(orderInfo.OrderDate);
                this.txtRequestedDeliveryDate.Text = base.GetPreferenceShortDate(orderInfo.RequestedDeliveryDate);
                this.txtOwnerID.Text = orderInfo.OwnerID;
                this.txtOwnerID.Enabled = false;
                this.imgOwnerID.Visible = false;
                this.ddlPriority.SelectedValue = orderInfo.Priority;
                this.txtExternOrderID.Text = orderInfo.ExternOrderID;
                this.ddlTransportMode.SelectedValue = orderInfo.TransportationMode;
                this.txtActualShipDate.Text = base.GetPreferenceShortDate(orderInfo.ActualShipDate);
                this.txtConsigneeID.Text = orderInfo.ConsigneeID;
                this.txtC_Company.Text = orderInfo.CCompany;
                this.txtC_City.Text = orderInfo.CCity;
                this.txtC_Prov.Text = orderInfo.CProv;
                this.txtC_Contact1.Text = orderInfo.CContact1;
                this.txtC_Contact2.Text = orderInfo.CContact2;
                this.txtC_Zip.Text = orderInfo.CZip;
                this.txtC_Country.Text = orderInfo.CCountryCode;
                this.txtC_Phone1.Text = orderInfo.CPhone1;
                this.txtC_Phone2.Text = orderInfo.CPhone2;
                this.txtC_Address.Text = orderInfo.CAddress;
                this.txtC_Fax1.Text = orderInfo.CFax1;
                this.txtC_Fax2.Text = orderInfo.CFax2;
                this.txtC_Email1.Text = orderInfo.CEmail1;
                this.txtC_Email2.Text = orderInfo.CEmail2;
                this.txtBillToID.Text = orderInfo.BillToID;
                this.txtB_Company.Text = orderInfo.BCompany;
                this.txtB_City.Text = orderInfo.BCity;
                this.txtB_Prov.Text = orderInfo.BState;
                this.txtB_Contact1.Text = orderInfo.BContact1;
                this.txtB_Contact2.Text = orderInfo.BContact2;
                this.txtB_Zip.Text = orderInfo.BZip;
                this.txtB_Country.Text = orderInfo.BCountryCode;
                this.txtB_Phone1.Text = orderInfo.BPhone1;
                this.txtB_Phone2.Text = orderInfo.BPhone2;
                this.txtB_Address.Text = orderInfo.BAddress;
                this.txtB_Fax1.Text = orderInfo.BFax1;
                this.txtB_Fax2.Text = orderInfo.BFax2;
                this.txtB_Email1.Text = orderInfo.BEmail1;
                this.txtB_Email2.Text = orderInfo.BEmail2;
                this.txtRemark.Text = orderInfo.Remark;
                this.txtUdf1.Text = orderInfo.Udf1;
                this.txtUdf2.Text = orderInfo.Udf2;
                this.txtUdf3.Text = orderInfo.Udf3;
                this.txtUdf4.Text = orderInfo.Udf4;
                this.txtUdf5.Text = orderInfo.Udf5;
                this.txtUdf6.Text = orderInfo.Udf6;
                this.txtUdf7.Text = orderInfo.Udf7;
                this.txtUdf8.Text = orderInfo.Udf8;
                this.txtUdf9.Text = orderInfo.Udf9;
                this.txtUdf10.Text = orderInfo.Udf10;
                if ((orderInfo.SalesOrderDetailInfos != null) && (orderInfo.SalesOrderDetailInfos.Count > 0))
                {
                    this.hdnLineID.Value = (orderInfo.SalesOrderDetailInfos[orderInfo.SalesOrderDetailInfos.Count - 1].LineID + 10).ToString();
                }
                base.BindData2GridView(this.gvSalesOrderDetail, orderInfo.SalesOrderDetailInfos);
                this.txtOrderID.Enabled = false;
                this.txtOrderID1.Enabled = false;
                this.txtOrderID2.Enabled = false;
                this.EnableButton(this.ddlStatus.SelectedValue);
            }
        }

        protected void txtBillToID_TextChanged(object sender, EventArgs e)
        {
            BillingEntityInfo tradePartnerInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtBillToID.Text.Trim(), "BILLING_ENTITY") as BillingEntityInfo;
            if (!((tradePartnerInfo == null) || string.IsNullOrEmpty(tradePartnerInfo.BillingEntityID)))
            {
                this.txtB_Company.Text = tradePartnerInfo.Company;
                this.txtB_City.Text = tradePartnerInfo.City;
                this.txtB_Prov.Text = tradePartnerInfo.State;
                this.txtB_Zip.Text = tradePartnerInfo.Zip;
                this.txtB_Country.Text = tradePartnerInfo.Country;
                this.txtB_Address.Text = tradePartnerInfo.Address;
                this.txtB_Contact1.Text = tradePartnerInfo.Contact1;
                this.txtB_Phone1.Text = tradePartnerInfo.Phone1;
                this.txtB_Fax1.Text = tradePartnerInfo.Fax1;
                this.txtB_Email1.Text = tradePartnerInfo.Email1;
                this.txtB_Contact2.Text = tradePartnerInfo.Contact2;
                this.txtB_Phone2.Text = tradePartnerInfo.Phone2;
                this.txtB_Fax2.Text = tradePartnerInfo.Fax2;
                this.txtB_Email2.Text = tradePartnerInfo.Email2;
            }
            else
            {
                this.txtB_Company.Text = "";
                this.txtB_City.Text = "";
                this.txtB_Prov.Text = "";
                this.txtB_Zip.Text = "";
                this.txtB_Country.Text = "";
                this.txtB_Address.Text = "";
                this.txtB_Contact1.Text = "";
                this.txtB_Phone1.Text = "";
                this.txtB_Fax1.Text = "";
                this.txtB_Email1.Text = "";
                this.txtB_Contact2.Text = "";
                this.txtB_Phone2.Text = "";
                this.txtB_Fax2.Text = "";
                this.txtB_Email2.Text = "";
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,5);</script>", false);
            this.txtBillToID.Focus();
            this.hdnPageType.Value = "0";
        }

        protected void txtConsigneeID_TextChanged(object sender, EventArgs e)
        {
            CustomerInfo tradePartnerInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtConsigneeID.Text.Trim(), "CUSTOMER") as CustomerInfo;
            if (!((tradePartnerInfo == null) || string.IsNullOrEmpty(tradePartnerInfo.CustomerID)))
            {
                this.txtCustomerID.Text = tradePartnerInfo.CustomerID;
                this.txtConsigneeID.Text = tradePartnerInfo.CustomerID;
                this.txtC_Company.Text = tradePartnerInfo.Company;
                this.txtC_City.Text = tradePartnerInfo.City;
                this.txtC_Prov.Text = tradePartnerInfo.State;
                this.txtC_Zip.Text = tradePartnerInfo.Zip;
                this.txtC_Country.Text = tradePartnerInfo.Country;
                this.txtC_Address.Text = tradePartnerInfo.Address;
                this.txtC_Contact1.Text = tradePartnerInfo.Contact1;
                this.txtC_Phone1.Text = tradePartnerInfo.Phone1;
                this.txtC_Fax1.Text = tradePartnerInfo.Fax1;
                this.txtC_Email1.Text = tradePartnerInfo.Email1;
                this.txtC_Contact2.Text = tradePartnerInfo.Contact2;
                this.txtC_Phone2.Text = tradePartnerInfo.Phone2;
                this.txtC_Fax2.Text = tradePartnerInfo.Fax2;
                this.txtC_Email2.Text = tradePartnerInfo.Email2;
            }
            else
            {
                this.txtCustomerID.Text = this.txtConsigneeID.Text.Trim();
                this.txtC_Company.Text = "";
                this.txtC_City.Text = "";
                this.txtC_Prov.Text = "";
                this.txtC_Zip.Text = "";
                this.txtC_Country.Text = "";
                this.txtC_Address.Text = "";
                this.txtC_Contact1.Text = "";
                this.txtC_Phone1.Text = "";
                this.txtC_Fax1.Text = "";
                this.txtC_Email1.Text = "";
                this.txtC_Contact2.Text = "";
                this.txtC_Phone2.Text = "";
                this.txtC_Fax2.Text = "";
                this.txtC_Email2.Text = "";
            }
            this.txtConsigneeID.Focus();
            this.hdnPageType.Value = "0";
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,5);</script>", false);
        }

        protected void txtCustomerID_TextChanged(object sender, EventArgs e)
        {
            CustomerInfo tradePartnerInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtCustomerID.Text.Trim(), "CUSTOMER") as CustomerInfo;
            if (!((tradePartnerInfo == null) || string.IsNullOrEmpty(tradePartnerInfo.CustomerID)))
            {
                this.txtCustomerID.Text = tradePartnerInfo.CustomerID;
                this.txtConsigneeID.Text = tradePartnerInfo.CustomerID;
                this.txtC_Company.Text = tradePartnerInfo.Company;
                this.txtC_City.Text = tradePartnerInfo.City;
                this.txtC_Prov.Text = tradePartnerInfo.State;
                this.txtC_Zip.Text = tradePartnerInfo.Zip;
                this.txtC_Country.Text = tradePartnerInfo.Country;
                this.txtC_Address.Text = tradePartnerInfo.Address;
                this.txtC_Contact1.Text = tradePartnerInfo.Contact1;
                this.txtC_Phone1.Text = tradePartnerInfo.Phone1;
                this.txtC_Fax1.Text = tradePartnerInfo.Fax1;
                this.txtC_Email1.Text = tradePartnerInfo.Email1;
                this.txtC_Contact2.Text = tradePartnerInfo.Contact2;
                this.txtC_Phone2.Text = tradePartnerInfo.Phone2;
                this.txtC_Fax2.Text = tradePartnerInfo.Fax2;
                this.txtC_Email2.Text = tradePartnerInfo.Email2;
            }
            else
            {
                this.txtConsigneeID.Text = this.txtCustomerID.Text.Trim();
                this.txtC_Company.Text = "";
                this.txtC_City.Text = "";
                this.txtC_Prov.Text = "";
                this.txtC_Zip.Text = "";
                this.txtC_Country.Text = "";
                this.txtC_Address.Text = "";
                this.txtC_Contact1.Text = "";
                this.txtC_Phone1.Text = "";
                this.txtC_Fax1.Text = "";
                this.txtC_Email1.Text = "";
                this.txtC_Contact2.Text = "";
                this.txtC_Phone2.Text = "";
                this.txtC_Fax2.Text = "";
                this.txtC_Email2.Text = "";
            }
            this.txtCustomerID.Focus();
            this.hdnPageType.Value = "0";
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,5);</script>", false);
        }

        private void UpdateShippingOrderInfo()
        {
            try
            {
                if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                {
                    this.lblMsg.Text = "请输入货主代码!";
                }
                else if (string.IsNullOrEmpty(this.txtCustomerID.Text.Trim()))
                {
                    this.lblMsg.Text = "请输入客户代码!";
                }
                else if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7100_008");
                }
                else
                {
                    SalesOrderInfo ordersInfo = base.DataEntityViewState as SalesOrderInfo;
                    ordersInfo = this.SetOrdersInfo(ordersInfo);
                    ordersInfo.UpdatedBy = base.UserInfo.UserID;
                    this.lblMsg.Text = OrderMgtServiceClientProxy.GetInstance().UpdateSalesOrderInfo(ordersInfo) + base.GetGlobalMsgResource("F7100_009");
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F7100_010") + ex.Message;
            }
        }
    }
}

